/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package service;

import entity.Category;
import entity.CategoryFacadeLocal;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;

/**
 *
 * @author SONY
 */
@Stateless
public class CategoryService implements CategoryServiceLocal {
    
    @EJB CategoryFacadeLocal categoryFacadeLocal;

    @Override
    public List<Category> getAllCategories() {
        return categoryFacadeLocal.findAll();
    }

    @Override
    public Category getCategoryDetails_byCID(String cid) {
        return categoryFacadeLocal.find(cid);
    }

    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    public boolean addCategory(String cid, String cname) {
        try {
            Category category_add = new Category();
            category_add.setCategoryID(cid);
            category_add.setCategoryName(cname);
            categoryFacadeLocal.create(category_add);
            return true;
        } catch (Exception e) {
            System.err.println(e);
        }
        return false;
    }

}
